package twoD.hofem;

import inf.minife.fe.Model;
import inf.minife.sample.e1d.truss18;
import inf.minife.sample.e1d.archbridge.ArchBridge;
import inf.minife.sample.e2d.ConnectingRod2;
import inf.minife.sample.e3d.BuergiGardenCenter;
import inf.minife.view2.Viewer2;
import inf.minife.view2.mc.ModelCreateListener;
import inf.minife.view2.mc.ModelCreatorDialog;

public class InteractiveDemo {

	private static final Class<?>[] CLASSES_FOR_PACKAGES = { truss18.class,
			ConnectingRod2.class, BuergiGardenCenter.class, ArchBridge.class };

	public static String[] getPackageNames() {
		String[] names = new String[CLASSES_FOR_PACKAGES.length];

		for (int i = 0; i < names.length; i++) {
			names[i] = CLASSES_FOR_PACKAGES[i].getPackage().getName();
		}
		return names;
	}

	public static void main(String[] args) {
		System.out.println(System.getProperty("java.io.tmpdir"));

		new InteractiveDemo(new Viewer2(), CLASSES_FOR_PACKAGES);
	}

	public InteractiveDemo(final Viewer2 viewer2, Class<?>[] classesForPackages) {
		ModelCreatorDialog mcd = new ModelCreatorDialog(viewer2);
		mcd.addModelCreatedListener(new ModelCreateListener() {

			public void newModel(Object o) {
				if (o instanceof Model) {
					Model model = (Model) o;
					viewer2.setModel(model);
					viewer2.update();
				}
			}
		});

		for (Class<?> clzz : classesForPackages) {
			mcd.addFromPackage(clzz.getPackage().getName());
		}

		mcd.createList();
		mcd.pack();
		mcd.setResizable(false);
		mcd.setVisible(true);
		viewer2.setLocation(600, 0);
		viewer2.setVisible(true);
	}
}
